<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="&amp;#x524D;&amp;#x8A00;  &amp;#x6628;&amp;#x5929;&amp;#x521A;&amp;#x628A;socket tcp&amp;#x7F16;&amp;#x7A0B;&amp;#x7B80;&amp;#x5355;&amp;#x8BB2;&amp;#x89E3;&amp;#x4E86;&amp;#xFF0C;&amp;#x4ECA;&amp;#x5929;&amp;#x8D81;&amp;#x70ED;&amp;#x6253;&amp;#x94C1;&amp;#x628A;udp&amp;#x7F16;&amp;#x7A0B;&amp;">
<meta property="og:type" content="article">
<meta property="og:title" content="Android Socket编程（udp）初探">
<meta property="og:url" content="http://yoursite.com/2019/08/21/Android-Socket编程（udp）初探/index.html">
<meta property="og:site_name" content="Silence潇湘夜雨">
<meta property="og:description" content="&amp;#x524D;&amp;#x8A00;  &amp;#x6628;&amp;#x5929;&amp;#x521A;&amp;#x628A;socket tcp&amp;#x7F16;&amp;#x7A0B;&amp;#x7B80;&amp;#x5355;&amp;#x8BB2;&amp;#x89E3;&amp;#x4E86;&amp;#xFF0C;&amp;#x4ECA;&amp;#x5929;&amp;#x8D81;&amp;#x70ED;&amp;#x6253;&amp;#x94C1;&amp;#x628A;udp&amp;#x7F16;&amp;#x7A0B;&amp;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/1716569-021209115a4e12a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/1716569-c396df1b7f103409.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2019-07-19T04:31:26.248Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android Socket编程（udp）初探">
<meta name="twitter:description" content="&amp;#x524D;&amp;#x8A00;  &amp;#x6628;&amp;#x5929;&amp;#x521A;&amp;#x628A;socket tcp&amp;#x7F16;&amp;#x7A0B;&amp;#x7B80;&amp;#x5355;&amp;#x8BB2;&amp;#x89E3;&amp;#x4E86;&amp;#xFF0C;&amp;#x4ECA;&amp;#x5929;&amp;#x8D81;&amp;#x70ED;&amp;#x6253;&amp;#x94C1;&amp;#x628A;udp&amp;#x7F16;&amp;#x7A0B;&amp;">
<meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/1716569-021209115a4e12a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/08/21/Android-Socket编程（udp）初探/">





  <title>Android Socket编程（udp）初探 | Silence潇湘夜雨</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Silence潇湘夜雨</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Android开发一枚</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home //首页"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user //关于"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags  //标签"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th //分类"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive //归档"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-schedule">
          <a href="/schedule/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-calendar //日程表"></i> <br>
            
            日程表
          </a>
        </li>
      
        
        <li class="menu-item menu-item-sitemap">
          <a href="/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap //站点地图"></i> <br>
            
            站点地图
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/08/21/Android-Socket编程（udp）初探/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Silence潇湘夜雨">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Silence潇湘夜雨">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android Socket编程（udp）初探</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-08-21T15:51:43+08:00">
                2019-08-21
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/socket/" itemprop="url" rel="index">
                    <span itemprop="name">socket</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  900
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  5
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="&#x524D;&#x8A00;"><a href="#&#x524D;&#x8A00;" class="headerlink" title="&#x524D;&#x8A00;"></a>&#x524D;&#x8A00;</h3><p>  &#x6628;&#x5929;&#x521A;&#x628A;socket tcp&#x7F16;&#x7A0B;&#x7B80;&#x5355;&#x8BB2;&#x89E3;&#x4E86;&#xFF0C;&#x4ECA;&#x5929;&#x8D81;&#x70ED;&#x6253;&#x94C1;&#x628A;udp&#x7F16;&#x7A0B;&#x4E5F;&#x8BB2;&#x4E00;&#x4E0B;&#x3002;&#x4E00;&#x4E2A;&#x662F;&#x4E3A;&#x4E86;&#x63D0;&#x9192;&#x81EA;&#x5DF1;&#xFF0C;&#x575A;&#x6301;&#x4E0B;&#x53BB;&#xFF0C;&#x53E6;&#x5916;&#x8FD8;&#x662F;&#x4E3A;&#x4E86;&#x63D0;&#x5347;&#x6280;&#x672F;&#x6253;&#x4E0B;&#x57FA;&#x7840;&#x3002;&#x5982;&#x679C;&#x8BB2;&#x7684;&#x6709;&#x4EC0;&#x4E48;&#x4E0D;&#x5BF9;&#x7684;&#x8FD8;&#x8BF7;&#x5404;&#x4F4D;&#x6307;&#x6B63;&#x3002;</p>
<h3 id="&#x9996;&#x5148;"><a href="#&#x9996;&#x5148;" class="headerlink" title="&#x9996;&#x5148;"></a>&#x9996;&#x5148;</h3><p> &#x5148;&#x4E0A;&#x56FE;&#xFF0C;&#x4FD7;&#x8BDD;&#x8BF4;no pic say a xx<br><img src="https://upload-images.jianshu.io/upload_images/1716569-021209115a4e12a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="udp&#x7F16;&#x7A0B;&#x670D;&#x52A1;&#x7AEF;.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/1716569-c396df1b7f103409.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="udp&#x7F16;&#x7A0B;&#x5BA2;&#x6237;&#x7AEF;.png"></p>
<h3 id="&#x5176;&#x6B21;"><a href="#&#x5176;&#x6B21;" class="headerlink" title="&#x5176;&#x6B21;"></a>&#x5176;&#x6B21;</h3><ul>
<li><p>&#x5BA2;&#x6237;&#x7AEF;&#x4EE3;&#x7801;&#xFF08;&#x7EBF;&#x7A0B;&#x4E2D;&#xFF09;</p>
<pre><code>public class UdpClientThread extends Thread {

//IP&#x5730;&#x5740;
private String mAddress;
//&#x7AEF;&#x53E3;
private int port;
//&#x53D1;&#x9001;&#x5185;&#x5BB9;
private String msg;
private Handler mHandler;

public UdpClientThread(Handler handler, String address, int port, String msg) {
  this.mHandler = handler;
  this.mAddress = address;
  this.port = port;
  this.msg = msg;
}

@Override
public void run() {
  super.run();
  sendSocket();
}

/**
 * &#x8BBE;&#x7F6E;
 */
private void sendSocket() {
  byte[] bytes = msg.getBytes();
  try {
      /*******************&#x53D1;&#x9001;&#x6570;&#x636E;***********************/
      InetAddress address = InetAddress.getByName(mAddress);
      //1.&#x6784;&#x9020;&#x6570;&#x636E;&#x5305;
      DatagramPacket packet = new DatagramPacket(bytes, 
bytes.length, address, port);
      //2.&#x521B;&#x5EFA;&#x6570;&#x636E;&#x62A5;&#x5957;&#x63A5;&#x5B57;&#x5E76;&#x5C06;&#x5176;&#x7ED1;&#x5B9A;&#x5230;&#x672C;&#x5730;&#x4E3B;&#x673A;&#x4E0A;&#x7684;&#x6307;&#x5B9A;&#x7AEF;&#x53E3;&#x3002;
      DatagramSocket socket = new DatagramSocket();
      //3.&#x4ECE;&#x6B64;&#x5957;&#x63A5;&#x5B57;&#x53D1;&#x9001;&#x6570;&#x636E;&#x62A5;&#x5305;&#x3002;
      socket.send(packet);
      /*******************&#x63A5;&#x6536;&#x6570;&#x636E;***********************/
      //1.&#x6784;&#x9020; DatagramPacket&#xFF0C;&#x7528;&#x6765;&#x63A5;&#x6536;&#x957F;&#x5EA6;&#x4E3A; length &#x7684;&#x6570;&#x636E;&#x5305;&#x3002;
      final byte[] bytes1 = new byte[1024];
      DatagramPacket receiverPacket = new DatagramPacket(bytes1, bytes1.length);
      socket.receive(receiverPacket);
      sendMsg(0,new String(bytes1, 0, bytes1.length));
      socket.close();
  } catch (UnknownHostException e) {
      e.printStackTrace();
  } catch (SocketException e) {
      e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }
}

/**
 * &#x53D1;&#x9001;&#x6D88;&#x606F;
 */
private void sendMsg(int what, Object object) {
  Message msg = new Message();
  msg.what = what;
  msg.obj = object;
  mHandler.sendMessage(msg);
 }
 }</code></pre><p><strong>&#x8BF4;&#x660E;:</strong>&#x8FD9;&#x91CC;&#x7684;&#x5C01;&#x88C5;&#x548C;tcp&#x4E2D;&#x7684;&#x4E00;&#x6837;&#xFF0C;&#x5C31;&#x662F;&#x6362;&#x4E00;&#x4E0B;&#x53C2;&#x6570;&#x548C;&#x5305;&#x88C5;&#x7C7B;&#xFF0C;&#x4EE3;&#x7801;&#x4E2D;&#x7684;&#x89E3;&#x91CA;&#x90FD;&#x6BD4;&#x8F83;&#x6E05;&#x695A;&#x3002;</p>
</li>
<li><p>&#x5BA2;&#x6237;&#x7AEF;&#xFF08;&#x4F7F;&#x7528;&#xFF09;</p>
<pre><code>public class UdpClientActivity extends AppCompatActivity
  implements View.OnClickListener {

Button mBtnSend;
String mAddress = &quot;192.168.0.197&quot;;
int port = 12306;
TextView mTxtContent;
EditText mEdtContent;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_udp_client);
  initView();
}

private void initView() {
  mEdtContent = findViewById(R.id.edt_udp_content);
  mBtnSend = findViewById(R.id.btn_udp_send);
  mTxtContent = findViewById(R.id.txt_udp_content);
  mBtnSend.setOnClickListener(this);
}</code></pre></li>
</ul>
<pre><code>@Override
public void onClick(View view) {
  switch (view.getId()) {
      case R.id.btn_udp_send: {
          UdpClientThread mThread = new UdpClientThread(mHandler, mAddress, port,
                  mEdtContent.getText().toString());
          mThread.start();
          break;
      }
  }
}

/**
 * Handler
 */
private Handler mHandler = new Handler(Looper.myLooper()) {
  @Override
  public void handleMessage(Message msg) {
      super.handleMessage(msg);
      switch (msg.what) {
          case 0: {
              String content = (String) msg.obj;
              mTxtContent.setText(content);
              break;
          }
      }
  }
};
}</code></pre><p><strong>&#x8BF4;&#x660E;&#xFF1A;</strong>&#x8FD9;&#x91CC;&#x76F4;&#x63A5;&#x70B9;&#x51FB;&#x6309;&#x94AE;&#x8C03;&#x7528;&#x7EBF;&#x7A0B;&#x4F7F;&#x7528;&#x5373;&#x53EF;&#xFF0C;&#x5F53;&#x7136;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x7528;&#x7EBF;&#x7A0B;&#x6C60;&#x6765;&#x6784;&#x9020;&#x53C2;&#x6570;&#x3002;</p>
<ul>
<li><p>&#x670D;&#x52A1;&#x7AEF;&#xFF08;&#x4EE3;&#x7801;&#xFF09;</p>
<pre><code>public class UdpServer {

    /**
     * @param args
     */
      public static void main(String[] args) {
      while (true) {
         getMsg();
      }
      }

    /**
     * &#x83B7;&#x53D6;&#x4FE1;&#x606F;
     */

       private static void getMsg() {
       try {
    &#x200B;    byte[] buf = new byte[1024];
    &#x200B;    // &#x4E00;&#x3001;&#x63A5;&#x6536;&#x6570;&#x636E;
    &#x200B;    // 1&#x3001;&#x521B;&#x5EFA;&#x63A5;&#x6536;&#x6570;&#x636E;&#x7684;&#x6570;&#x636E;&#x5305;
    &#x200B;    DatagramPacket packet = new DatagramPacket(buf, buf.length);
    &#x200B;    // 2.&#x521B;&#x5EFA;UPD &#x7684; socket
    &#x200B;    DatagramSocket socket = new DatagramSocket(12306);
    &#x200B;    // 3&#x3001;&#x63A5;&#x6536;&#x6570;&#x636E;
    &#x200B;    System.out.println(&quot;&#x670D;&#x52A1;&#x7AEF;&#x5F00;&#x59CB;&#x76D1;&#x542C;&#xFF01;~~~~&quot;);
    &#x200B;    socket.receive(packet);
    &#x200B;    // 4&#x3001;&#x5904;&#x7406;&#x6570;&#x636E;
    &#x200B;    System.out.println(&quot;&#x670D;&#x52A1;&#x7AEF;&#xFF1A;&quot; + new String(buf, 0, buf.length));

        // &#x4E8C;&#x3001;&#x8FD4;&#x56DE;&#x6570;&#x636E;
        DatagramPacket packet2 = new DatagramPacket(buf, buf.length,
                packet.getAddress(), packet.getPort());
        socket.send(packet2);
        socket.close();
    } catch (Exception e) {
    &#x200B;    e.printStackTrace();
    }

 }

}</code></pre><h3 id="&#x6700;&#x540E;"><a href="#&#x6700;&#x540E;" class="headerlink" title="&#x6700;&#x540E;"></a>&#x6700;&#x540E;</h3><p>&#x5520;&#x53E8;&#x4E00;&#x4E0B;&#xFF0C;&#x505A;&#x4E8B;&#x4E00;&#x5B9A;&#x8981;&#x5584;&#x59CB;&#x5584;&#x7EC8;&#xFF0C;&#x505A;&#x4EBA;&#x4E00;&#x5B9A;&#x8981;&#x8BDA;&#x4FE1;&#xFF08;ps&#xFF1A;&#x6700;&#x8FD1;&#x9047;&#x5230;&#x4E86;&#x4E00;&#x4E2A;&#x4E0D;&#x8BDA;&#x4FE1;&#x7684;&#x516C;&#x53F8;&#xFF0C;offer&#x53D1;&#x4E86;&#x4E4B;&#x540E;&#xFF0C;&#x7B2C;&#x4E8C;&#x5929;&#x544A;&#x8BC9;&#x6211;&#x4E0D;&#x7528;&#x53BB;&#x4E86;&#xFF0C;&#x95EE;&#x8FC7;&#x539F;&#x56E0;&#x4E4B;&#x540E;&#xFF0C;&#x4EBA;&#x4E8B;&#x548C;&#x8001;&#x677F;&#x52A9;&#x7406;&#x56DE;&#x590D;&#x8FD8;&#x4E0D;&#x4E00;&#x6837;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x6709;&#x70B9;&#x597D;&#x73A9;&#x4E86;&#xFF0C;&#x771F;&#x7684;&#x662F;&#x8D8A;&#x60F3;&#x8D8A;&#x751F;&#x6C14;&#x3002;&#x5C24;&#x5176;&#x662F;&#x5BF9;&#x4E8E;&#x6211;&#x8FD9;&#x79CD;&#x5BF9;&#x8BDA;&#x4FE1;&#x6BD4;&#x8F83;&#x770B;&#x91CD;&#x7684;&#x4EBA;&#xFF0C;&#x771F;&#x7684;&#x662F;&#x4E0D;&#x80FD;&#x5FCD;&#x3002;&#x7279;&#x522B;&#x75DB;&#x6068;&#x90A3;&#x79CD;&#x7B54;&#x5E94;&#x522B;&#x4EBA;&#x5374;&#x505A;&#x4E0D;&#x5230;&#x7684;&#x4EBA;&#xFF0C;&#x8981;&#x4E0D;&#x5C31;&#x522B;&#x7B54;&#x5E94;&#xFF0C;&#x8981;&#x4E0D;&#x5C31;&#x505A;&#x5230;&#x3002;&#x6211;&#x4E00;&#x822C;&#x7B54;&#x5E94;&#x522B;&#x4EBA;&#x7684;&#x4E8B;&#x60C5;&#xFF0C;&#x4E00;&#x5B9A;&#x4F1A;&#x505A;&#x5230;&#xFF0C;&#x4E0D;&#x7BA1;&#x6211;&#x8981;&#x4ED8;&#x51FA;&#x4EC0;&#x4E48;&#xFF0C;&#x8D77;&#x7801;&#x6211;&#x5151;&#x73B0;&#x4E86;&#x81EA;&#x5DF1;&#x7684;&#x627F;&#x8BFA;&#x3002;&#xFF09;&#x3002;&#x53D1;&#x4E86;&#x4E00;&#x987F;&#x7262;&#x9A9A;&#xFF0C;&#x8FD8;&#x8BF7;&#x5404;&#x4F4D;&#x770B;&#x5B98;&#x89C1;&#x8C05;&#x3002;</p>
<h3 id="&#x81F4;&#x8C22;"><a href="#&#x81F4;&#x8C22;" class="headerlink" title="&#x81F4;&#x8C22;"></a>&#x81F4;&#x8C22;</h3><p><a href="https://www.jianshu.com/p/fb4dfab4eec1" target="_blank" rel="noopener">Android&#x7F51;&#x7EDC;&#x7F16;&#x7A0B;&#x4E4B;&#x2013;Socket&#x7F16;&#x7A0B;</a></p>
</li>
</ul>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/08/21/Android-Socket编程（tcp）初探/" rel="next" title="Android Socket编程（tcp）初探">
                <i class="fa fa-chevron-left"></i> Android Socket编程（tcp）初探
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/08/21/Android-socket高级用法（自定义协议和Protocol-Buffer使用）/" rel="prev" title="Android socket高级用法（自定义协议和Protocol Buffer使用）">
                Android socket高级用法（自定义协议和Protocol Buffer使用） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Silence潇湘夜雨</p>
              <p class="site-description motion-element" itemprop="description">Android开发一枚</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">55</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/muyishuangfeng" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/1e2eec6f972c" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-heartbeat"></i>简书</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://juejin.im/user/58df0abf61ff4b006b115e43" target="_blank" title="掘金">
                      
                        <i class="fa fa-fw fa-star"></i>掘金</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://twitter.com/yangke20792452" target="_blank" title="Twitter">
                      
                        <i class="fa fa-fw fa-twitter"></i>Twitter</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#首先"><span class="nav-number">2.</span> <span class="nav-text">首先</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#其次"><span class="nav-number">3.</span> <span class="nav-text">其次</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#最后"><span class="nav-number">4.</span> <span class="nav-text">最后</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#致谢"><span class="nav-number">5.</span> <span class="nav-text">致谢</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Silence潇湘夜雨</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">114.8k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

  <!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618},"display":{"superSample":2,"width":150,"height":300,"position":"right","hOffset":0,"vOffset":-20},"mobile":{"show":false},"react":{"opacityDefault":0.5,"opacityOnHover":0.5},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
